import React, { Component } from 'react';
import { Modal, Button } from 'antd';

export default class AddMenu extends Component{

    constructor(props){
        super(props);
        this.state = { visible: true };
    }

    componentDidMount(){
        // 订阅添加笔记显示的显示属性
        this.pubsub_visible = PubSub.subscribe('public_visible', function (topic, message) {  
            this.setState({  
                visible: message  
            });  
        }.bind(this));  
    }

    componentWillUnmount(){
        // 组件将要移除时取消订阅  
        PubSub.unsubscribe(this.pubsub_visible);  
    }

    handleOk = (e) => {
        PubSub.publish('visible', false);
    }

    handleCancel = (e) => {
        PubSub.publish('visible', false);
        PubSub.publish('public_menu', 'Biji');
    }

    render(){
        console.log(this.state.visible);
        return (
            <div>
                <Modal className="add-biji-model" title="添加笔记" visible={ this.state.visible } onOk={ this.handleOk } onCancel={ this.handleCancel }>
                    <p>Some contents...</p>
                    <p>Some contents...</p>
                    <p>Some contents...</p>
                </Modal>
            </div>
        );
    }
}